﻿using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
using System.Security.Claims;

namespace SimpleSaasAuth.Configuration
{
	/// <summary>
	/// 其他服务可以通过这里获取token的解析信息
	/// </summary>
	public class CustomProfileService : IProfileService
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		/// <returns></returns>
		public Task GetProfileDataAsync(ProfileDataRequestContext context)
		{
			context.IssuedClaims.AddRange(
				context.Subject.Claims.Where(x =>
							x.Type.Equals(ClaimTypes.NameIdentifier)
							|| x.Type.Equals(ClaimTypes.Name)
							|| x.Type.Equals("phoneNumber")
							|| x.Type.Equals("tenantId")
							|| x.Type.Equals("tenantName")
							|| x.Type.Equals("databaseId")
			));
			return Task.CompletedTask;
		}

		public Task IsActiveAsync(IsActiveContext context)
		{
			context.IsActive = true;
			return Task.CompletedTask;
		}
	}
}